package com.jrew.gae.wcs.spring.controllers;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractCommandController;

import com.jrew.gae.wcs.entities.PlayerStats;
import com.jrew.gae.wcs.spring.services.StatsManagerService;

/**
 *
 */
public class SavePlayerStatsController extends AbstractCommandController {

	/**
	 * 
	 */
	private StatsManagerService statsManagerService;
	
	/**
	 * 
	 */
	private String viewName;
	
	/**
	 * 
	 */
	public SavePlayerStatsController() {
		setCommandClass(PlayerStats.class);
	}
	
	@Override
	protected ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception {
		PlayerStats playerStats = (PlayerStats) command; 
		statsManagerService.updatePlayerStats(playerStats);
		return new ModelAndView(viewName, null);
	}

	/**
	 * @return
	 */
	public StatsManagerService getStatsManagerService() {
		return statsManagerService;
	}

	/**
	 * @param statsManagerService
	 */
	public void setStatsManagerService(StatsManagerService statsManagerService) {
		this.statsManagerService = statsManagerService;
	}

	/**
	 * @return
	 */
	public String getViewName() {
		return viewName;
	}

	/**
	 * @param viewName
	 */
	public void setViewName(String viewName) {
		this.viewName = viewName;
	}
}
